package com.huluobo.a2204parkdemo.park

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import com.huluobo.a2204parkdemo.R
import com.huluobo.a2204parkdemo.adapter.ParkingAdapter
import com.huluobo.a2204parkdemo.databinding.ActivityParkingBinding
import com.huluobo.base.bean.ParkingBean
import com.huluobo.base.bean.ParkingBeanItem
import com.huluobo.base.mvvm.BaseActivity
import com.huluobo.base.net.Const
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ParkingActivity : BaseActivity<ActivityParkingBinding, ParkViewModel>() {
    private lateinit var parkingAdapter: ParkingAdapter
    override fun initData() {
        viewModel.queryParkSuccess.observe(this) {
            val list = Gson().fromJson(it, ParkingBean::class.java)
            parkingAdapter.data.clear()
            parkingAdapter.data.addAll(list)
            parkingAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.parkingHeader.headerTitle.text = "车位申请"
        binding.parkingHeader.headerBack.setOnClickListener { finish() }
        binding.parkingHeader.headerAdd.visibility = View.VISIBLE

        binding.parkingRv.layoutManager = LinearLayoutManager(this)
        parkingAdapter = ParkingAdapter()
        binding.parkingRv.adapter = parkingAdapter

        parkingAdapter.setOnItemClickListener { adapter, view, position ->
            val intent = Intent(this, ParkingVRActivity::class.java)
            intent.putExtra(Const.INTENT_PARK_BEAN, parkingAdapter.data[position])
            startActivity(intent)
        }
    }

    override fun onResume() {
        super.onResume()
        viewModel.queryAllParking()
    }
}